package com.emergency.direct.controller;

import com.emergency.base.domain.Message;
import com.emergency.base.domain.Scenar;
import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.direct.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by lijie on 2019/10/21.
 */
@RestController
@RequestMapping("/message")
@Api(value="文书指挥类",description = "通过文书发布和接受命令接口")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ApiOperation(value = "文书查询接口" ,notes="可以查询当前登录人的收件箱，可按时间和状态返回")
    @RequestMapping(value = "list/{page}/{size}",method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){

        Page<Message> pageList = messageService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK,  "操作成功", pageList);
    }

    @ApiOperation(value = "文书发送接口",notes="可以查询当前登录人的收件箱")
    @RequestMapping(value = "send",method = RequestMethod.POST)
    public Result send (@RequestBody Message message){

        String messageId=messageService.saveOrUpdate(message);

        return new Result(true, StatusCode.OK,  "操作成功", "");
    }

    @ApiOperation(value = "文书获取接口",notes="可以查询文书具体内容")
    @RequestMapping(value = "info",method = RequestMethod.GET)
    public Result info (Long messageId){

        Message message=messageService.getMessageById(messageId);
        return new Result(true, StatusCode.OK,  "操作成功", message);
    }


    @ApiOperation(value = "文书指令结果获取",notes="从第三方接收器返回指令执行情况")
    @RequestMapping(value = "update",method = RequestMethod.GET)
    public Result update (@RequestBody String message){

        return new Result(true, StatusCode.OK,  "操作成功", message);
    }
}
